package io.bba.boot.system.controller;

import io.bba.boot.auth.annotation.Permission;
import io.bba.boot.common.enums.SysLogType;
import io.bba.boot.framework.annotation.Log;
import io.bba.boot.framework.page.Paging;
import io.bba.boot.framework.response.ApiResult;
import io.bba.boot.system.dto.SysBannerDto;
import io.bba.boot.system.query.SysBannerQuery;
import io.bba.boot.system.service.SysBannerService;
import io.bba.boot.system.vo.SysBannerVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 系统轮播图 控制器
 *
 * @author xxcj
 * @since 2024-03-13
 */
@Slf4j
@RestController
@Tag(name = "系统轮播图")
@RequestMapping("/admin/sysBanner")
public class SysBannerController {

    @Autowired
    private SysBannerService sysBannerService;

    /**
     * 添加系统轮播图
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    @Operation(summary = "添加系统轮播图")
    @PostMapping("/addSysBanner")
    @Permission("sys:banner:add")
    public ApiResult addSysBanner(@Valid @RequestBody SysBannerDto dto) {
        log.info("添加系统轮播图：{}", dto);
        boolean flag = sysBannerService.addSysBanner(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改系统轮播图
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    @Operation(summary = "修改系统轮播图")
    @PostMapping("/updateSysBanner")
    @Permission("sys:banner:update")
    public ApiResult updateSysBanner(@Valid @RequestBody SysBannerDto dto) {
        log.info("修改系统轮播图：{}", dto);
        boolean flag = sysBannerService.updateSysBanner(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除系统轮播图
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    @Operation(summary = "删除系统轮播图")
    @PostMapping("/deleteSysBanner/{id}")
    @Permission("sys:banner:delete")
    public ApiResult deleteSysBanner(@PathVariable Long id) {
        log.info("删除系统轮播图：{}", id);
        boolean flag = sysBannerService.deleteSysBanner(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取系统轮播图详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取系统轮播图详情")
    @PostMapping("/getSysBanner/{id}")
    @Permission("sys:banner:info")
    public ApiResult<SysBannerVo> getSysBanner(@PathVariable Long id) {
        log.info("获取系统轮播图详情：{}", id);
        SysBannerVo sysBannerVo = sysBannerService.getSysBannerById(id);
        return ApiResult.success(sysBannerVo);
    }

    /**
     * 获取系统轮播图分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取系统轮播图分页列表")
    @PostMapping("/getSysBannerPage")
    @Permission("sys:banner:page")
    public ApiResult<SysBannerVo> getSysBannerPage(@Valid @RequestBody SysBannerQuery query) {
        log.info("获取系统轮播图分页列表：{}", query);
        Paging<SysBannerVo> paging = sysBannerService.getSysBannerPage(query);
        return ApiResult.success(paging);
    }

}
